<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        var str = "aabccd";
        // 创建空对象存储结果
        var obj = {};
        // 遍历字符串
        for (var i = 0; i < str.length; i++) {
            // 将位置i所对应的字符赋给j
            var j = str.charAt(i);
            // 判断这个字符的属性值
            if (obj[j] == undefined) {
                obj[j] = 1;
            } else {
                obj[j]++;
            }
        }
        // 打印对象
        console.log(obj);
    </script>
</body>

</html>